import { createI18n } from 'vue-i18n'
import zhEl from 'element-plus/es/locale/lang/zh-cn'
import enEl from 'element-plus/es/locale/lang/en'
import zh from './json/zh.json'
import en from './json/en.json'

export const localesEl: any = {
  zh: zhEl,
  en: enEl
}

export const langs = [
  { key: 'zh', title: '简体中文' },
  { key: 'en', title: 'English' }
]

// 获取浏览器界面语言，默认语言
const locale = localStorage.getItem('locale') || navigator.language.replace(/-(\S*)/, '') || ''

export default createI18n({
  locale: locale,
  legacy: false, // 修复组件引入i18n时vite脚手架报错的问题
  globalInjection: true, // 全局注册 $t
  messages: {
    zh,
    en
  }
})
